(function (lib, config) {
    var loadFunc = function () {
        var textAry = config.words.split('|'), bgcolorAry = config.bgcolor.split('|'), textcolorAry = config.textcolor.split('|'), imglinkAry = config.imglink.split('|'), weblinkAry = config.weblink.split('|'), identiAry = config.identifier.split('|');
        textAry[0] = textAry[0] || '在线健康顾问';
        textAry[1] = textAry[1] || '您好，今天是咱们妇科主任亲诊<span>（每周仅1次）</span>，点击一对一咨询';
        textAry[2] = textAry[2] || '最近身体哪里不舒服呢？<span>说说看你的症状</span>（对话已加密，请放心咨询）';
        textAry[3] = textAry[3] || '还在关注吗？我这边会在线等待<font color=\"red\">15<\/font>秒哦！';
        textAry[4] = textAry[4] || '请在此输入';
        textAry[5] = textAry[5] || '发送';
        textcolorAry[0] = textcolorAry[0] || '#000';
        textcolorAry[1] = textcolorAry[1] || '#333';
        textcolorAry[2] = textcolorAry[2] || '#e7453a';
        textcolorAry[3] = textcolorAry[3] || '#e7453a';
        textcolorAry[4] = textcolorAry[4] || '#fff';
        textcolorAry[5] = textcolorAry[5] || '#c2c2c2';
        bgcolorAry[0] = bgcolorAry[0] || '#f2f2f2';
        bgcolorAry[1] = bgcolorAry[1] || '#fff';
        bgcolorAry[2] = bgcolorAry[2] || '#e7453a';
        imglinkAry[0] = imglinkAry[0] || 'http://wap.hdyy.com.cn/swt/js20161206/img/swt_zj.jpg';
        imglinkAry[1] = imglinkAry[1] || 'http://wap.hdyy.com.cn/swt/js20161206/img/mclose.png';
        imglinkAry[2] = imglinkAry[2] || 'http://wap.hdyy.com.cn/swt/js20161206/img/swt_sr.png';
        identiAry[0] = identiAry[0] || 'swt_zhongjian';
        function getScrollTop() {
            var scrollTop = 0;
            if (document.documentElement && document.documentElement.scrollTop) {
                scrollTop = document.documentElement.scrollTop;
            }
            else if (document.body) {
                scrollTop = document.body.scrollTop;
            }
            return scrollTop;
        }
        function getClientHeight() { //获取可视高度
            var clientHeight = 0;
            if (document.body.clientHeight && document.documentElement.clientHeight) {
                var clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
            }
            else {
                var clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
            }
            return clientHeight;
        }
        var _ua = navigator.userAgent, _ua_text = false, _position = "fixed";
        if (_ua.indexOf('baiduboxapp') > -1) {
            _ua_text = true; _position = "absolute";
        }

        var htmlStr = [];
        htmlStr.push("<style type=\"text/css\">");
        htmlStr.push("body{font-family:\"microsoft yahei\";}");/*right: 0; top:40%*/
        htmlStr.push("#LR-BUBBLE{ position:" + _position + "; "+lib.util.getPosStyle(config)+";  display:block; width: 90%;margin: 0 5% 10vh 5% !important;background-color:" + bgcolorAry[0] + " !important; color: " + textcolorAry[0] + "; text-align: left; box-shadow: 0 5px 16px 0 rgba(0, 0, 0, .16);  border-radius:10px; z-index: 9999999;border:2px solid #fff;pointer-events:auto;}");
        htmlStr.push("#LR-BUBBLE-INSIDE{ text-align: left; line-height:20px;padding:5px; height:auto;margin:0 10px!important;}");
        htmlStr.push("#LR-BUBBLE-CLOSE { position: absolute; top:3px; right: 3px; width: 26px; height: 26px;background-image:url(" + imglinkAry[1] + ");border-radius:100%;background-size:100%;background-position:0 0;}");
        htmlStr.push("#LR-BUBBLE-MSG {height:auto!important;margin-top: 5px; font-size: 14px; overflow: hidden; color: " + textcolorAry[1] + ";max-height:100px;}");
        htmlStr.push("#LR-BUBBLE-MSG span{color:" + textcolorAry[2] + ";}");
        htmlStr.push("#LR-BUBBLE-NAME {display:block;line-height:35px;font-weight:bold;color: " + textcolorAry[0] + "; font-size: 14px;margin:0 0 0 40px!important;}");
        htmlStr.push("#LR-BUBBLE-AVATAR {display:block;float:left;width: 35px; height: 35px; border-radius:100%; margin-right: 6px; vertical-align: top; box-shadow: 0 0 8px 0 rgba(0, 0, 0, .15); }");
        htmlStr.push(".footerdh{padding:8px 10px;background:" + bgcolorAry[1] + ";}");
        htmlStr.push(".footerdh img{display:block;width:20px;float:left;margin-top:3px;}");
        htmlStr.push(".footerdh a{display:block;float:right;background:" + bgcolorAry[2] + ";color:" + textcolorAry[4] + ";width:60px;height:22px;line-height:22px;border-radius:2px;text-align:center;font-size:14px;}");
        htmlStr.push(".footerdh span{display:block;margin:0 67px 0 26px;border-bottom:1px solid #e7453a;height:21px;line-height:21px;color:" + textcolorAry[4] + ";font-size:14px;}");
        htmlStr.push("#LRdiv3{display:none!important;}");
        htmlStr.push("</style>");
        htmlStr.push("<div id=\"LR-BUBBLE\">");
        htmlStr.push("    <span id=\"LR-BUBBLE-CLOSE\" onclick=\"closebar();\"></span>");
        htmlStr.push("    <div id=\'LR-BUBBLE-INSIDE\' onclick=\"openZoosUrl('"+identiAry[0]+"');\"><div id=\'LR-BUBBLE-title\' style=\'display: block;\'><img id=\'LR-BUBBLE-AVATAR\' src=\'" + imglinkAry[0] + "\'><span id=\'LR-BUBBLE-NAME\'>" + textAry[0] + "</span></div><div id=\'LR-BUBBLE-MSG\'></div></div>");
        htmlStr.push("    <div class=\"footerdh\" onclick=\"openZoosUrl('"+identiAry[0]+"');\"><img src=\"" + imglinkAry[2] + "\"/><a style='color:"+textcolorAry[5]+"'>" + textAry[5] + "</a><span>" + textAry[4] + "</span></div>");
        htmlStr.push("</div>");
        htmlStr.push("<style type=\'text/css\'>");
        htmlStr.push("#LR-BUBBLE { -webkit-animation: shake-little 10s both infinite; -moz-animation: shake-little 10s both infinite; -ms-animation: shake-little 10s both infinite; animation: shake-little 10s both infinite; }");
        htmlStr.push("@-webkit-keyframes shake-little { 0, 20% {");
        htmlStr.push(" -webkit-transform: translate(0px, 0px) rotate(0deg)");
        htmlStr.push("}");
        htmlStr.push("21% {");
        htmlStr.push(" -webkit-transform: translate(0px, 0px) rotate(0deg)");
        htmlStr.push("}");
        htmlStr.push("21.3% {");
        htmlStr.push(" -webkit-transform: translate(-2px, 2px) rotate(0.5deg)");
        htmlStr.push("}");
        htmlStr.push("21.6% {");
        htmlStr.push(" -webkit-transform: translate(0px, 0px) rotate(0deg)");
        htmlStr.push("}");
        htmlStr.push("22% {");
        htmlStr.push(" -webkit-transform: translate(2px, -2px) rotate(-0.5deg)");
        htmlStr.push("}");
        htmlStr.push("22.3% {");
        htmlStr.push(" -webkit-transform: translate(0px, 0px) rotate(0deg)");
        htmlStr.push("}");
        htmlStr.push("22.6% {");
        htmlStr.push(" -webkit-transform: translate(-2px, 2px) rotate(0.5deg)");
        htmlStr.push("}");
        htmlStr.push("23% {");
        htmlStr.push(" -webkit-transform: translate(0px, 0px) rotate(0deg)");
        htmlStr.push("}");
        htmlStr.push("23.3% {");
        htmlStr.push(" -webkit-transform: translate(2px, -2px) rotate(-0.5deg)");
        htmlStr.push("}");
        htmlStr.push("23.6% {");
        htmlStr.push(" -webkit-transform: translate(0px, 0px) rotate(0deg)");
        htmlStr.push("}");
        htmlStr.push("24% {");
        htmlStr.push(" -webkit-transform: translate(2px, -2px) rotate(-0.5deg)");
        htmlStr.push("}");
        htmlStr.push("24.3%, 100% {");
        htmlStr.push(" -webkit-transform: translate(0px, 0px) rotate(0deg)");
        htmlStr.push("}");
        htmlStr.push("}");
        htmlStr.push("</style>");
        var o = document.createElement('div');
        o.innerHTML = htmlStr.join('');
        while (o.firstElementChild) {
            document.body.appendChild(o.firstElementChild);
        };

        function toolkey() {
            document.getElementById('LR-BUBBLE').style.display = 'block';
            setStyleVal('LR-BUBBLE-MSG',textAry[1],textcolorAry[1]);
            setTimeout(toolkey2, 10000);
            if (config.eachtime > 0) setTimeout(closebar,config.eachtime*1000);
        };
        function toolkey2() {
            setStyleVal('LR-BUBBLE-MSG', textAry[2], textcolorAry[2]);
            setTimeout(toolkey3, 10000);
        };
        function toolkey3() {
            setStyleVal('LR-BUBBLE-MSG', textAry[3], textcolorAry[3]);
        };
        setTimeout(toolkey, config.firsttime * 1000);
        closebar = function () {
            document.getElementById('LR-BUBBLE').style.display = 'none';
            setTimeout(toolkey, config.relapsetime * 1000);
        };
        function setStyleVal(id,innerHTML,color) {
            var ele = document.getElementById(id);
            ele.innerHTML = innerHTML;
            ele.style.color = color;
        }
        function addEvent(obj, type, fn) {
            if (obj.attachEvent) {
                obj.attachEvent('on' + type, function () {
                    fn.call(obj);
                })
            } else {
                obj.addEventListener(type, fn, false);
            }
        }
        if (_ua_text) {
            var _t = document.getElementById('LR-BUBBLE').style.top;
            window.onscroll = function () {
                document.getElementById('LR-BUBBLE').style.top = parseInt(_t) + (getScrollTop() / getClientHeight()) * 100 + '%';
            }
        }

    };
    lib.load(loadFunc);
})('{{lib}}', '{{config}}');